#! tclsh ps2pdf.tcl

proc absolve {fname} {
	regsub -all "\\\\" $fname "/" fname
	if {[regexp -nocase "^\[a-z\]+:" $fname]} {return $fname}
	set pwd [pwd]
	if {[string compare [string index $fname 0] "\/"] == 0} {
		if {![regexp -nocase "^\[a-z\]+:" $pwd drive]} {return $fname}
		return $drive$fname
	}
	return $pwd/$fname
}

if {[catch {

if {[llength $argv] == 0} {puts "Usage: tclsh gif2eps.tcl file.gif \[file.eps\]"; exit 0}
set giffile [absolve [lindex $argv 0]]
if {[string compare [file extension $giffile] .gif] != 0} {error "First argument should be a file with extension gif"}
if {[llength $argv] > 1} {
	set epsfile [absolve [lindex $argv 1]]
	if {![string compare [file extension $epsfile] .eps]} {error "Second argument should be a file with extension eps"}
} else {
	regsub ".gif\$" $giffile ".eps" epsfile
} 

cd "C:/Program Files/AutoTrace"

puts "autotrace.exe -filter-iterations 1 -output-format eps -output-file \"$epsfile\" \"$giffile\""
exec autotrace.exe -filter-iterations 1 -output-format eps -output-file "$epsfile" "$giffile"

} msg]} {puts "Error: $msg"; sleep 10; exit 1} 
